<template>
	<view class="page" style="height:100vh;background: #ededed;">
		<free-nav-bar showback :showright="false" title="设置朋友圈和权限">


		</free-nav-bar>
		<free-list-item title="不让他看我" showright :isshowjt="false">
			<switch :checked="form.lookme" @change="brtkw" v-model="form.lookme" slot="right" />
		</free-list-item>
		<free-list-item title="不看他" showright :isshowjt="false">
			<switch :checked="form.lookhim" @change="bkt" v-model="form.lookhim" slot="right" />
		</free-list-item>
	</view>
</template>

<script>
	import $H from '../../../utils/request.js';
	import freeNavBar from "@/components/free-ui/free-nav-bar.vue"
	import freeListItem from "@/components/free-ui/free-list-item.vue"
	export default {
		components: {
			freeNavBar,
			freeListItem
		},
		data() {
			return {
				form: {
					id: "",
					lookhim: false,
					lookme: false
				}
			}
		},
		onLoad(option) {
			console.log(option, "option")
			this.form.id = option.id;
			this.getdetail(option.id)
		},
		methods: {
			getdetail(id) {
				$H.post(`friend/read/${id}`, {
					token: true
				}).then(res => {

					if (res) {
						this.form.lookme = res.lookme == 0 ? true : false
						this.form.lookhim = res.lookhim == 0 ? true : false
					} else {
						uni.showToast({
							title: "该用户不存在",
							icon: none
						})
					}

				})
			},
			brtkw(e) {
				console.log(e, "e");
				this.form.lookme = e.detail.value
				let data = {
					lookme: this.form.lookme ? 0 : 1,
					lookhim: this.form.lookhim ? 0 : 1
				}
				$H.post("friend/setmomentauth/" + this.form.id, data, {
					token: true
				}).then(res => {
					console.log(res)
					if (res) {
											
						uni.showToast({
							title: '操作成功',
							icon: "none"
						});
					}
				})
			},
			bkt(e) {
				console.log(e, "e");
				this.form.lookhim = e.detail.value
				let data = {
					lookme: this.form.lookme ? 0 : 1,
					lookhim: this.form.lookhim ? 0 : 1
				}
				$H.post("friend/setmomentauth/" + this.form.id, data, {
					token: true
				}).then(res => {
					console.log(res)
					if (res) {
						
						uni.showToast({
							title: '操作成功',
							icon: "none"
						});
					}
				})
			},
		}
	}
</script>

<style>

</style>
